{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MNIST Dataset\n",
    "\n",
    "Here we try our first neural network using Keras, which is a high level library which wraps most of the functionality in tensorflow.\n",
    "\n",
    "Pay most attention to the section named `Keras Model`. The numpy, plotting functions should only be secondary considerations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting ./train-images-idx3-ubyte.gz\n",
      "Extracting ./train-labels-idx1-ubyte.gz\n",
      "Extracting ./t10k-images-idx3-ubyte.gz\n",
      "Extracting ./t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Dense\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "\n",
    "mnist = input_data.read_data_sets('./', one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 784)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x, y = mnist.train.next_batch(20)\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above extracted 20 images from disk. The 784 comes from the fact that its a flattened 28x28 image."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "784"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "28*28"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`y` is the one-hot encoded labels. Meaning instead of simply stating that label is 0-9, it puts a 1 where the label is supposed to be and 0 else where. See below to have a better understanding:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 10)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],\n",
       "       [ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],\n",
       "       [ 0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],\n",
       "       [ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.],\n",
       "       [ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],\n",
       "       [ 0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Visualise the first image (x[0]). Note that we need to reshape the flattened image before visualising:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADxlJREFUeJzt3X+QVfV5x/HPw7KAEoyg6WaLiFKBhOoUkxXThqZ2jIw6\ndMBM1NCJIZXp2haNmcloHTudOtNJx9gahxrjdIkoNsYfrbESa4lK25g0DmUxRAQKqEGF8kMDVZS4\nLsvTP/bgrLjne5d7z73nLs/7NbOz957nnHueueyHc+/93nO+5u4CEM+IshsAUA7CDwRF+IGgCD8Q\nFOEHgiL8QFCEHwiK8ANBEX4gqJGN3NkoG+1jNLaRuwRCeUdv613vsaGsW1P4zexCSUsktUj6jrvf\nnFp/jMbqXDu/ll0CSFjtq4a8btUv+82sRdIdki6SNEPSAjObUe3jAWisWt7zz5L0gru/5O7vSnpA\n0rxi2gJQb7WEf6KkVwfc354tex8z6zSzbjPr7lVPDbsDUKS6f9rv7l3u3uHuHa0aXe/dARiiWsK/\nQ9KkAfdPyZYBGAZqCf8aSVPN7HQzGyXpC5JWFNMWgHqreqjP3Q+a2dWSfqj+ob5l7r6hsM4A1FVN\n4/zu/rikxwvqBUAD8fVeICjCDwRF+IGgCD8QFOEHgiL8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U3y7pKTNba2adZTcziLZs2nRJ2iWprcxmBlFx\n5uZGOmJm6aZ57qqZ8bpofOD3QbPdfaakiyQtzl7eNiXvf8/WTMM1Q5q5uVEGmVn6PWU+d9XOeF20\nMsK/Q9KkAfdPyZY1BXffkf3eI+kRNd/sw7sPT5Ka/d5Tcj/vaaaZmwebWVpN8Nw104zXZYR/jaSp\nZna6mY2S9AVJK0ro4wPMbGz2QYzMbKykOWq+2YdXSFqY3V4o6dESe3mfZpm5OW9maZX83DXdjNfu\n3vAfSRer/xP/FyX9RRk95PQ1RdLPs58NZfcm6X71vwzsVf9nI4sknSRplaStkp6SNKGJevtHSesl\nPaf+oLWX1Nts9b+kf07Suuzn4rKfu0RfpTxvfMMPCIoP/ICgCD8QFOEHgiL8QFCEHwiK8ANBEX4g\nKMIPBPX/CCq2in9hm/4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7efe35dfccc0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(x[0].reshape(28,28))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Keras Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model = Sequential()\n",
    "model.add(Dense(100, activation='relu', input_dim=784))\n",
    "model.add(Dense(10, activation='softmax'))\n",
    "model.compile(loss='categorical_crossentropy',\n",
    "              optimizer='adam',\n",
    "              metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_1 (Dense)              (None, 100)               78500     \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 50)                5050      \n",
      "_________________________________________________________________\n",
      "dense_3 (Dense)              (None, 10)                510       \n",
      "=================================================================\n",
      "Total params: 84,060\n",
      "Trainable params: 84,060\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_batch(dataset, batch_size = 256):\n",
    "    while (1):\n",
    "        yield dataset.next_batch(batch_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2.3560128211975098, 0.099058493589743585]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "batch_size = 256\n",
    "test_gen = get_batch(mnist.test, batch_size)\n",
    "steps_per_epoch = mnist.test.num_examples// batch_size\n",
    "model.evaluate_generator(test_gen, steps_per_epoch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/1\n",
      "214/214 [==============================] - 1s - loss: 0.4610 - acc: 0.8701     \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7efe2d709550>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "batch_size = 256\n",
    "data_gen = get_batch(mnist.train, batch_size)\n",
    "steps_per_epoch = mnist.train.num_examples//batch_size\n",
    "\n",
    "model.fit_generator(data_gen, steps_per_epoch, epochs=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.2156959095987204, 0.94127847546728971]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.evaluate_generator(test_gen, steps_per_epoch)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It is really important to be able to reload the model after you've been training it for hours on end (usually). So save the model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from keras.models import load_model\n",
    "\n",
    "model.save('my_model.h5')\n",
    "\n",
    "model2 = load_model('my_model.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.21581618651469178, 0.94118720794392519]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model2.evaluate_generator(test_gen, steps_per_epoch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x, y = next(test_gen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(256, 784)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  5.89663614e-05,   2.18626178e-06,   1.17566145e-04,\n",
       "          9.36167594e-03,   5.95077081e-03,   2.00801552e-03,\n",
       "          3.26015902e-06,   8.21015462e-02,   7.07899802e-04,\n",
       "          8.99688184e-01],\n",
       "       [  2.79192493e-04,   4.06867638e-03,   2.33969302e-03,\n",
       "          9.35589015e-01,   2.49429066e-02,   9.76238865e-03,\n",
       "          5.27733355e-04,   9.19848867e-03,   2.51918798e-03,\n",
       "          1.07726818e-02]], dtype=float32)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7efe247765f8>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADmdJREFUeJzt3X+QVfV5x/HPw7IsESQRTXYoEJCASdCZYLMFM9pMEpKU\nUFO0zThSmyEddc2MOiaTprV2pnWm/YOpNdapqc7aUCBNjJlRC53BpspYaVJFVkIFpAmEbBS6/DCo\nEE1gfzz9Yw/Oqnu+9+aee++5y/N+zezs3fOcc88zZ/hw7r3fe87X3F0A4plQdgMAykH4gaAIPxAU\n4QeCIvxAUIQfCIrwA0ERfiAowg8ENbGZO5tkHT5ZU5q5SyCUX+k1nfKTVs26hcJvZssk3S2pTdI/\nufvq1PqTNUVLbGmRXQJI2Oqbq1635pf9ZtYm6euSPiNpoaSVZraw1ucD0FxF3vMvlrTP3fe7+ylJ\n35G0oj5tAWi0IuGfKenFUX8fyJa9iZl1m1mvmfUO6GSB3QGop4Z/2u/uPe7e5e5d7epo9O4AVKlI\n+A9Kmj3q71nZMgDjQJHwb5O0wMzON7NJkq6WtLE+bQFotJqH+tx90MxukvQ9jQz1rXH33XXrDEBD\nFRrnd/dNkjbVqRcATcTXe4GgCD8QFOEHgiL8QFCEHwiK8ANBEX4gKMIPBEX4gaAIPxAU4QeCIvxA\nUIQfCIrwA0ERfiAowg8ERfiBoAg/EBThB4Ii/EBQhB8IivADQRF+ICjCDwRF+IGgCD8QFOEHgiL8\nQFCEHwiq0Cy9ZtYn6YSkIUmD7t5Vj6YANF6h8Gc+7u4v1eF5ADQRL/uBoIqG3yU9bmbPmll3PRoC\n0BxFX/Zf5u4Hzew9kh4zs/919y2jV8j+U+iWpMk6q+DuANRLoTO/ux/Mfh+R9IikxWOs0+PuXe7e\n1a6OIrsDUEc1h9/MppjZ2acfS/q0pF31agxAY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rwA0GZuzdvZ2ZHJf1s1KLz1LoXjLdqb63al0Rvtapnb3Pc/d3VrNjU8L9t52a97t5V\nWgMJrdpbq/Yl0VutyuqNl/1AUIQfCKrs8PeUvP+UVu2tVfuS6K1WpfRW6nt+AOUp+8wPoCSlhN/M\nlpnZj8xsn5ndWkYPecysz8x2mtkOM+stuZc1ZnbEzHaNWjbdzB4zs73Z7zGnSSupt9vN7GB27HaY\n2fKSepttZk+Y2fNmttvMbsmWl3rsEn2Vctya/rLfzNok/VjSpyQdkLRN0kp3f76pjeQwsz5JXe5e\n+piwmX1U0i8krXf3i7JlfyvpmLuvzv7jPMfd/6xFertd0i/Knrk5m1BmxuiZpSVdIekLKvHYJfq6\nSiUctzLO/Isl7XP3/e5+StJ3JK0ooY+W5+5bJB17y+IVktZlj9dp5B9P0+X01hLcvd/dt2ePT0g6\nPbN0qccu0Vcpygj/TEkvjvr7gFprym+X9LiZPWtm3WU3M4bObNp0STokqbPMZsZQcebmZnrLzNIt\nc+xqmfG63vjA7+0uc/dFkj4j6cbs5W1L8pH3bK00XFPVzM3NMsbM0m8o89jVOuN1vZUR/oOSZo/6\ne1a2rCW4+8Hs9xFJj6j1Zh8+fHqS1Oz3kZL7eUMrzdw81szSaoFj10ozXpcR/m2SFpjZ+WY2SdLV\nkjaW0MfbmNmU7IMYmdkUSZ9W680+vFHSquzxKkkbSuzlTVpl5ua8maVV8rFruRmv3b3pP5KWa+QT\n/59I+osyesjpa56k/8l+dpfdm6QHNPIycEAjn41cK+lcSZsl7ZX0uKTpLdTbNyXtlPScRoI2o6Te\nLtPIS/rnJO3IfpaXfewSfZVy3PiGHxAUH/gBQRF+ICjCDwRF+IGgCD8QFOEHgiL8QFCEHwjq/wHm\nQU9t8dejIAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7efe2d769748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(x[0].reshape(28,28))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7efe246ab400>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADepJREFUeJzt3X+MHHUZx/HP0+u1lKPFXsGzgaYFJQgUKXgWQSRo5aeQ\nQjTFmkBN0GKCjUSIEEwUjTH4i8ZfQQ9pKIpYtWIbQ1CoRqLByoGlLbTIr1NaSw9asAVL27t7/OOm\n5oCb7y67sztbnvcrudzuPDM7T7b93Ozud3a+5u4CEM+YshsAUA7CDwRF+IGgCD8QFOEHgiL8QFCE\nHwiK8ANBEX4gqLHN3Nk4G+8HqKOZuwRCeUUva4/vtmrWrSv8ZnaOpO9IapP0Y3e/IbX+AerQyTan\nnl0CSFjtq6pet+aX/WbWJukHks6VdKyk+WZ2bK2PB6C56nnPP1vSE+7+lLvvkfRzSXOLaQtAo9UT\n/sMkPTPi/qZs2auY2UIz6zWz3r3aXcfuABSp4Z/2u3uPu3e7e3e7xjd6dwCqVE/4N0uaNuL+4dky\nAPuBesL/gKSjzOwIMxsn6WOSVhbTFoBGq3moz90HzOwzkn6n4aG+Je7+SGGdAWiousb53f0uSXcV\n1AuAJuL0XiAowg8ERfiBoAg/EBThB4Ii/EBQhB8IivADQRF+ICjCDwRF+IGgCD8QFOEHgiL8QFCE\nHwiK8ANBEX4gKMIPBEX4gaAIPxAU4QeCauoU3WiMrvsn5dZum35fcttBH0rWT1/30WR93OLOZP3A\ntZtyawNbnk1ui8biyA8ERfiBoAg/EBThB4Ii/EBQhB8IivADQdU1zm9mfZJ2ShqUNODu3UU0hTfm\n6W8ek1s78W0zk9sesm5Xsv7vS9P/Rf508+Jk/ewln8+tTVk3Pbltx/LVy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D61m\nxaaG/3U7N+t19+7SGkho1d5atS+J3mpVVm+87AeCIvxAUGWHv6fk/ae0am+t2pdEb7UqpbdS3/MD\nKE/ZR34AJSkl/GZ2jpk9ZmZPmNm1ZfSQx8z6zGxdNvNwb8m9LDGzfjNbP2JZp5ndY2aPZ79HnSat\npN5aYubmxMzSpT53rTbjddNf9ptZm6R/SDpT0iZJD0ia7+6PNrWRHGbWJ6nb3UsfEzaz0yW9JOk2\nd5+ZLfuGpO3ufkP2h3Oyu1/TIr1dL+mlsmduziaUmTpyZmlJF0r6hEp87hJ9zVMJz1sZR/7Zkp5w\n96fcfY+kn0uaW0IfLc/d75O0/TWL50pamt1equH/PE2X01tLcPct7v5QdnunpH0zS5f63CX6KkUZ\n4T9M0jMj7m9Sa0357ZLuNbMHzWxh2c2MoiubNl2SnpXUVWYzo6g4c3MzvWZm6ZZ57mqZ8bpofOD3\neqe5+yxJ50q6Int525J8+D1bKw3XVDVzc7OMMrP0/5X53NU643XRygj/ZknTRtw/PFvWEtx9c/a7\nX9Kdar3Zh7fumyQ1+91fcj//10ozN482s7Ra4LlrpRmvywj/A5KOMrMjzGycpI9JWllCH69jZh3Z\nBzEysw5JZ6n1Zh9eKWlBdnuBpBUl9vIqrTJzc97M0ir5uWu5Ga/dvek/ks7T8Cf+T0r6Qhk95PR1\npKSHs59Hyu5N0h0afhm4V8OfjVwmaYqkVZIel3SvpM4W6u0nktZJWqvhoE0tqbfTNPySfq2kNdnP\neWU/d4m+SnneOMMPCIoP/ICgCD8QFOEHgiL8QFCEHwiK8ANBEX4gKMIPBPU/yMQ/ALOR9q0AAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7efe2888ff28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(x[1].reshape(28,28))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2/2 [==============================] - 0s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([9, 3])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict_classes(x[:2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Conclusion\n",
    "\n",
    "There are only 3 things you need to remember from this lesson.\n",
    "1. Model Architecture.\n",
    "2. model.fit(), don't worry too much about the generator part just yet. When you do lesson 5 we will ignore the generator functions. This is only useful if the data is too big to fit in memory. Essentially `fit()` is used to train your model.\n",
    "3. model.predict() and model.predict_classes()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "latex_envs": {
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 0
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
